/**
 * Project Name:kany-utils
 * File Name:LocationUtils.java
 * Package Name:me.kany.utils.baidu.map
 * Date:2016年4月23日上午7:48:43
 * Copyright (c) 2016, Jason.Wang All Rights Reserved.
 *
*/

package me.kany.utils.baidu.map;

import com.alibaba.fastjson.JSONObject;

import blade.kit.DateKit;
import blade.kit.http.HttpRequest;

/**
 * ClassName:LocationUtils <br/>
 * Function: 百度的地图操作类型. <br/>
 * Date:     2016年4月23日 上午7:48:43 <br/>
 * @author   Jason.Wang
 * @version  
 * @since    JDK 1.7
 * @see 	 
 */
public class LocationUtils {
	private final static String API_ADDRESS_URL = "http://api.map.baidu.com/geocoder/v2/";
	private final static String API_IP_URL = "http://api.map.baidu.com/location/ip";	
	private final static String API_AK = "0vYIs0gxZ82DSRIINqEcZu1cnKvc6ZME";
	
	/**
	 * 
	 * getLocationByAddress:根据地址获取当前的坐标信息. <br/>
	 *
	 * @author Jason.Wang
	 * @param address
	 * @return
	 * @since JDK 1.7
	 */
	public static JSONObject getLocationByAddress(String address) {
		HttpRequest request = HttpRequest.post(API_ADDRESS_URL, true, "ak", API_AK, "output", "json", "address", address, "_", DateKit.getCurrentUnixTime());
		String res = request.body();
		request.disconnect();
		return JSONObject.parseObject(res);
	}
	
	/**
	 * 
	 * getLocationByIP:根据IP地址获取当前的坐标信息. <br/>
	 *
	 * @author Jason.Wang
	 * @param ipAddress
	 * @return
	 * @since JDK 1.7
	 */
	public static JSONObject getLocationByIP(String ipAddress) {
		HttpRequest request = HttpRequest.post(API_IP_URL, true, "ak", API_AK, "ip", ipAddress, "coor", "bd09ll");
		String res = request.body();
		request.disconnect();
		return JSONObject.parseObject(res);
	}

}
